<?php

	define(IMPORT,'../class.mamatblog/',true);
	require_once(IMPORT.'mysql.php');
	require_once(IMPORT.'comment.php');
	
	$pageDetailId = addslashes($_GET['page']);
	
	//comment
	$comm = new Comment();
	
	$out = "";
	
	//add comment
	if((empty($_GET['name']) or empty($_GET['email']) or empty($_GET['website']) or empty($_GET['message'])) and ($_GET['send']==1)){
		$out .= "<b>Isi Form dengan lengkap, yak :)</b>";
	} else if(!empty($_GET['name']) and !empty($_GET['email']) and !empty($_GET['website']) and !empty($_GET['message']) and ($_GET['send'] == 1)){
		$name =$_GET['name'];
		$email = $_GET['email'];
		$website = $_GET['website'];
		$message = $_GET['message'];
		
		if($comm->addComment($name, $email, $website, $message, $pageDetailId)){
			$out .= "<b>Add comment Sukses :)</b>";
		} else {
			$out .= "<b>Add Comment Gagal :(, format email harus benar..!</b>";
		}
	}
	
	
	//comment data
	$dataComment = $comm->getComment($pageDetailId);
	if(empty($dataComment)){
		$out .= "<br/>No Comments :)";
	} else {
		$out .= "<ul>";
		for($i = 0; $i < count($dataComment); $i++) {
		
			$out .= "
				<li><a href = '".$dataComment[$i][3]."'>".$dataComment[$i][1]."</a>[".$dataComment[$i][2]."]  | ".$dataComment[$i][6]."</li>".nl2br($dataComment[$i][4])."
			";
		
		}
		$out .= "</ul>";
	}
		
?>

<p>
<h3>Comment</h3>
<?php echo $out;?>
</p>

<p>
<h3>Add Comment</h3>
	<form name="msg">
	  
	    Name:
	      <input name="name" type="text" size="10">
	    Email:
	    <input name="email" type="text" size="15"><br/>
	    Web:
	    <input name="website" type="text" size="20"><br/>
	    <textarea name="message" cols="35" rows="4"></textarea>
	    <br/>
      	<input type="reset" value="Send" onClick="sendMessage('maincomment.php?page=<?php echo $pageDetailId;?>&','comment','Loading Send Message..!','msg','name','email','website','message');">
	</form>
</p>


<br/>
<h3>Describtion</h3>